from django.contrib import admin
from django.utils.html import format_html

from .models import LocDevices


class LocDevicesAdmin(admin.ModelAdmin):
    list_display = [ 'location_id', "status" , 'custom_location_name']

    list_display_links = ('location_id', ) # 默认
    # sortable_by # 排序

    '''定义哪个字段可以编辑'''
    list_editable = ('status', )

    '''分页：每页10条'''
    list_per_page = 30

    '''搜索框 ^, =, @, None=icontains'''
    search_fields = ['location_name']

    '''最大条目'''
    list_max_show_all = 200  # default

    '''按日期分组'''
    # date_hierarchy = '没有日期'

    '''默认空值'''
    empty_value_display = 'NA'

    '''过滤选项'''
    list_filter = ('status', )


    def custom_location_name(self, obj):
        return obj.location_name

    def custom_status(self, obj):
        return obj.status

    def location_id(self, obj):
        return obj.location_id


    custom_location_name.short_description = '设备位置名称'
    custom_status.short_description = '状态'
    location_id.short_description = '位置id'



# Register your models here.
admin.site.register(LocDevices, LocDevicesAdmin)

